{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "# Building histograms using Rectangles and PolyCollections\n",
    "\n",
    "\n",
    "Using a path patch to draw rectangles.\n",
    "The technique of using lots of Rectangle instances, or\n",
    "the faster method of using PolyCollections, were implemented before we\n",
    "had proper paths with moveto/lineto, closepoly etc in mpl.  Now that\n",
    "we have them, we can draw collections of regularly shaped objects with\n",
    "homogeneous properties more efficiently with a PathCollection.  This\n",
    "example makes a histogram -- its more work to set up the vertex arrays\n",
    "at the outset, but it should be much faster for large numbers of\n",
    "objects\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAD8CAYAAAB6paOMAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAEN1JREFUeJzt3XGsnXV9x/H3h1ZwGYuimMzQAnV2i3U60FpdyNAoQlXSmgxjSdxgYWl0krmQZeJcIKshEU3csg0j3Wzi3FxFXMwdqSFMcMtiwFZAsLDOSxW4qQmTMtgCwgrf/XEe3fF4yn3uvef23tvf+5Wc8Dy/5/d77vfXX+mnz/Occ5qqQpLUrhOWugBJ0tIyCCSpcQaBJDXOIJCkxhkEktQ4g0CSGmcQSFLjDAJJapxBIEmNW73UBYw64YRVVfXcUpchSSvND6vqZfMZuOyCoOo5zvjwTUtdxnHjwWsv9Ndzgvz1nCx/PSfnwWsvfHC+Y701JEmNMwgkqXEGgSQ1ziCQpMYZBJLUOINAkhpnEEhS4wwCSWqcQSBJjTMIJKlxBoEkNc4gkKTGGQSS1DiDQJIaZxBIUu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ktS4/wOGyyv2V/tsHQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.patches as patches\n",
    "import matplotlib.path as path\n",
    "\n",
    "fig, ax = plt.subplots()\n",
    "\n",
    "# Fixing random state for reproducibility\n",
    "np.random.seed(19680801)\n",
    "\n",
    "\n",
    "# histogram our data with numpy\n",
    "\n",
    "data =[1,2,3,4]\n",
    "n, bins = np.histogram(data, 4,density=True)\n",
    "\n",
    "# get the corners of the rectangles for the histogram\n",
    "left = np.array(bins[:-1])\n",
    "right = np.array(bins[1:])\n",
    "bottom = np.zeros(len(left))\n",
    "top = bottom + n\n",
    "\n",
    "\n",
    "# we need a (numrects x numsides x 2) numpy array for the path helper\n",
    "# function to build a compound path\n",
    "XY = np.array([[left, left, right, right], [bottom, top, top, bottom]]).T\n",
    "\n",
    "# get the Path object\n",
    "barpath = path.Path.make_compound_path_from_polys(XY)\n",
    "\n",
    "# make a patch out of it\n",
    "patch = patches.PathPatch(barpath)\n",
    "ax.add_patch(patch)\n",
    "\n",
    "# update the view limits\n",
    "ax.set_xlim(left[0], right[-1])\n",
    "ax.set_ylim(bottom.min(), top.max())\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
